package com.whalehearing.tingyou.api.controller.user;

import com.whalehearing.tingyou.domain.User;
import com.whalehearing.tingyou.service.IUserService;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.enums.BusinessType;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 用户信息Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-26
 */
@Api(tags = "Api用户信息管理")
@RestController
@RequestMapping("/api/user/user")
public class ApiUserController extends BaseController {
    @Autowired
    private IUserService userService;


    /**
     * 用户注册
     */
    @ApiOperation("用户注册")
    @Log(title = "用户注册", businessType = BusinessType.INSERT)
    @PostMapping("/register")
    public AjaxResult register(@RequestBody User user) {
        return AjaxResult.success(userService.register(user));
    }


    /**
     * 获取用户信息详细信息
     */
    @ApiOperation("获取用户信息详细信息")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(userService.getById(userId));
    }

    /**
     * 修改用户信息
     */
    @ApiOperation("修改用户信息")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody User user) {
        return toAjax(userService.updateById(user));
    }

    /**
     * 删除用户信息
     */
    @ApiOperation("删除用户信息")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(userService.removeByIds(Arrays.asList(userIds)));
    }
}
